<script>
import UText from "../../../uni_modules/uview-ui/components/u-text/u-text.vue";
import UButton from "../../../uni_modules/uview-ui/components/u-button/u-button.vue";
import store from "../../../store";
import { getUserInfoApi } from '../../../api/common/user';

export default {
  name: "index",
  components: {UButton, UText },
  data(){
    return {
      user: {
        loginName: '',
        phonenumber: '',
      }
    }
  },
  mounted(){
    this.init()
  },
  methods: {
    async init(){
      const { user } = await getUserInfoApi();
      this.user = user;
    },
    // toOrder() {
    //   uni.navigateTo({
    //     url: "/pages/index/mine/order/index"
    //   });
    // },
    toSetting() {
      uni.navigateTo({
        url: "/pages/index/mine/setting/index"
      });
    },
    toContactUs() {
      uni.navigateTo({
        url: "/pages/index/mine/contact-us/index"
      });
    },
    logout() {
      uni.showModal({
        title: "提示",
        content: "确定退出登录吗？",
        success: () => {
          store.dispatch("user/logout").then(() => {
            console.log('用户退出成功', store.getters['user/token'])
            uni.showToast({
              title: "退出成功",
              icon: "none"
            });
            uni.reLaunch({
              url: "/pages/login/index"
            });
          });
        }
      });
    }
  }
}
</script>

<template>
  <view class="page">
    <view class="head">背景图片</view>
    <view class="content">
      <view class="info">
        <view class="cell">
          <view class="cell-hd">
            <u-icon name="account-fill" size="30"></u-icon>
          </view>
          <view class="cell-bd">
            <view class="name">{{user.loginName}}</view>
            <view class="phone">{{user.phonenumber}}</view>
          </view>
        </view>
      </view>
      <!--<view class="item" @click="toOrder">-->
      <!--  <view class="cell">-->
      <!--    <view class="cell-hd">[icon]</view>-->
      <!--    <view class="cell-bd">我的订单</view>-->
      <!--  </view>-->
      <!--</view>-->
      <view class="item" @click="toSetting">
        <view class="cell">
          <view class="cell-hd">
            <u-icon name="setting" size="20"></u-icon>
          </view>
          <view class="cell-bd">设置</view>
        </view>
      </view>
      <view class="item" @click="toContactUs">
        <view class="cell">
          <view class="cell-hd">
            <u-icon name="phone" size="20"></u-icon>
          </view>
          <view class="cell-bd">联系我们</view>
        </view>
      </view>
    </view>
    <view class="footer">
      <u-button
          type="primary"
          class="footer-btn"
          @click="logout"
      >退出登录</u-button>
    </view>
  </view>
</template>

<style scoped lang="scss">
.page{
  *{
    box-sizing: border-box;
  }
}
.head{
  width: 100%;
  display: block;
  background: var(--blue);
  height: 100px;
}
.content{
  width: 100%;
  box-sizing: border-box;
  display: block;
  padding: 10px;
  margin-top: -50px;
  box-sizing: border-box;
  .info{
    padding: 20px;
    background-color: #fff;
    border-radius: 10px;
    width: 100%;
    display: block;
    font-size: 16px;
    margin-bottom: 15px;
    box-sizing: border-box;
    .name{
      font-size: 16px;
    }
    .phone{
      font-size: 14px;
      color: #888;
      margin-top: 10px;
    }
    .cell-bd{
      padding: 0 10px;
    }
  }
  .item{
    padding: 20px;
    background-color: #fff;
    border-radius: 10px;
    width: 100%;
    box-sizing: border-box;
    display: block;
    font-size: 16px;
    margin-bottom: 15px;
    .cell-bd{
      padding: 0 15px;
    }
  }
}
//吸底按钮
.footer{
  width: 100%;
  display: block;
  position: fixed;
  right: 0;
  bottom: 80px;
  padding: 20px;
  box-sizing: border-box;
}
</style>
